#!/bin/bash
# 在CentOS中安装mysql从库的脚本
# 需要设置从库的server-id和主库的参数

yum install -y mariadb mariadb-server

echo '[mysqld]
server-id=2' > /etc/my.cnf.d/slave.cnf

systemctl start mariadb

mysqladmin --user=root --password= password qjx36uGC

mysql --user=root --password=qjx36uGC -e "CHANGE MASTER TO
    MASTER_HOST='10.0.0.7', 
    MASTER_USER='slave',
    MASTER_PASSWORD='AnfONgWS',
    MASTER_LOG_FILE='mysql-bin.000003',
    MASTER_LOG_POS=685;
start slave;
show slave status\G;"


mysql --user=root --password=qjx36uGC -e "show slave status\G;"
